<template>
  <div class="expert_header">
    <div class="header2">
      <div class="fl header_left">
        <img src="../../../static/images/header_logo.png" />
        <p>欢迎您：<span class="comAccount">{{userName}}</span></p>
      </div>

      <div class="fr header_right">
        <router-link to='waitAssess'
                     class="indexBtn"></router-link>
        <div class="userBox">
          <div class="user clearfix">
            <span>{{userName}}</span>
          </div>
          <ul class="user_list">
            <li>
              <router-link to='changepsd2'><i class="el-icon-unlock"></i> 修改密码</router-link>
            </li>
            <li>
              <router-link to='uploadSign'><i class="el-icon-paperclip"></i> 上传签名</router-link>
            </li>
            <li><a @click="exitFlag=true"><i class="el-icon-switch-button"></i> 安全退出</a></li>
          </ul>
        </div>
      </div>
    </div>

    <ul class="nav clearfix">
      <li class="active">
        <router-link to="waitAssess">应急预案评审</router-link>
      </li>
      <!-- <li><router-link to="waitAssess">应急能力评估</router-link></li> -->
    </ul>

    <el-dialog title="系统提示"
               :visible.sync="exitFlag"
               width="30%"
               :append-to-body="true">
      <span class="exitTcNote"><img src='../../../static/images/warn_icon.png' />确认要退出吗？</span>
      <span slot="footer"
            class="dialog-footer">
        <input @click="exit"
               type="button"
               value="确 认"
               class="tcSubmit" />
        <input @click="exitFlag = false"
               type="button"
               value="取 消"
               class="tcCancel" />
      </span>
    </el-dialog>
  </div>
</template>

<script>
import config from "../../config.js";
export default {
  name: '',
  data () {
    return {
      exitFlag: false,
      companyName: '',
      userName: ''
    }
  },
  mounted () {
    if (localStorage.userid) {
      this.getInfo()
      if(JSON.parse(localStorage.user).userType == 1){
            this.$router.push('index')
        }
    } else {
      this.$message.warning('请登录后查看')
      this.$router.push('login')
    }
  },
  computed: {

  },
  methods: {
    getInfo () {
      this.$axios.post(config.baseUrl + 'emergency/v1.0/personal/info', { userId: localStorage.userid })
        .then((res) => {
          // console.log(res)
          /* if (res.data.meta.success) {
            this.companyName = res.data.data.companyName
            this.userName = res.data.data.userName
          } else {
            console.log(res.data.meta.message)
          } */
          if (res.data.meta.success) {
            this.companyName = res.data.data.companyName;
            this.$store.state.loginstates = res.data.data.userType;
            this.userName = res.data.data.userName
          } else {
            if(res.data.meta.message == 'repeat login'){
                this.$message.warning('检测到账号重复登录，如非本人操作，为了账号安全，请您尽快修改密码！')
                this.$router.push('login')
            }else if(res.data.meta.message == '服务异常，未获取到token的值'){
                this.$message.warning('服务异常，请重新登录！')
                this.$router.push('login')
            }
          }

        }).catch((response) => {
          console.log(response);
        })
    },
    exit () {
      this.$axios.post(config.baseUrl + "emergency/v1.0/user/logout", { userId: localStorage.userid })
        .then(res => {
          if (res.data.meta.success) {
            this.exitFlag = false
            for(var i in localStorage){
              if(i!='psdFlag'){
                  localStorage.removeItem(i)
              }
            }
            this.$router.push("login")
          } else {
            this.$message.warning(res.data.meta.message)
          }
        })
        .catch(response => {
          console.log(response);
        });
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang='less'>
.expert_header {
  position: fixed;
  top: 0;
  z-index: 2;
  width: 100%;
  .header2 {
    height: 58px;
    padding: 0 30px;
    background: url("../../../static/images/header_bg.png") no-repeat center
      center;
    width: 100%;
    min-width: 1200px;
    .header_left {
      line-height: 58px;
      height: 58px;
      p {
        display: inline;
        color: #fff;
        margin-left: 25px;
        font-size: 12px;
      }
    }
    .header_right {
      .indexBtn {
        background: url("../../../static/images/indexBtn.png") no-repeat;
        display: inline-block;
        height: 31px;
        width: 81px;
        border: 1px solid rgba(64, 128, 255, 0.6);
        border-radius: 8px;
        margin-top: 14px;
        margin-right: 20px;
      }
      .indexBtn:hover {
        border-color: #fff;
      }
      .userBox {
        float: right;
        position: relative;
        .user {
          line-height: 58px;
          padding: 0 15px;
          cursor: pointer;
          height: 58px;
          > img {
            height: 35px;
            width: 35px;
            border-radius: 50%;
            position: relative;
            top: -1px;
          }
          > span {
            color: #fff;
            margin-left: 15px;
            padding-right: 30px;
            background: url("../../../static/images/user_down.png") no-repeat
              right 10px center;
            display: inline-block;
            width: 100px;
            text-align: center;
            height: 58px;
          }
        }
        .user_list {
          width: 100%;
          border-radius: 0 0 8px 8px;
          background: #fff;
          display: none;
          position: absolute;
          z-index: 2;
          box-shadow: 1px 1px 10px rgba(207, 219, 241, 1);
          li {
            cursor: pointer;
            a {
              display: block;
              height: 48px;
              line-height: 48px;
              padding-left: 32px;
              color: #4080ff;
            }
          }
          li:last-child {
            border-radius: 0 0 8px 8px;
          }
          li:hover {
            background: #ecf2ff;
          }
        }
      }
      .userBox:hover {
        .user_list {
          display: block;
        }
      }
    }
  }
  .nav {
    height: 42px;
    background: #fff;
    box-shadow: 1px 1px 10px rgba(207, 219, 241, 1);
    padding: 0 30px;
    li {
      float: left;
      width: 98px;
      margin-right: 25px;
      text-align: center;
      height: 42px;
      line-height: 42px;
      cursor: pointer;
      a {
        color: #666;
      }
    }
    li.active,
    li:hover {
      border-bottom: 3px solid #4080ff;
      font-weight: bold;
      a {
        color: #4080ff;
      }
    }
  }
}
</style>
<style lang='less' scoped>
.exitTcNote {
  font-weight: bold;
  text-align: center;
  padding: 30px 0 20px;
  display: block;
  img {
    margin-right: 15px;
  }
}
.tcSubmit {
  height: 36px;
  width: 85px;
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  background: #4080ff;
 /* background: linear-gradient(left, #6fb2ff 0%, #095fff 100%);*/
}
.tcCancel {
  height: 36px;
  width: 85px;
  border: 1px solid #5ea0ff;
  color: #4080ff;
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  margin-left: 5px;
}
.tcSubmit:hover,
.tcCancel:hover {
  opacity: 0.8;
}
</style>

